<template>
  <div class="MoreNewDiscs" @mousewheel="showTop">
    <!-- 顶部导航栏 -->
    <TopNav :typess="typess" />
    <!-- 头部导航栏 -->
    <HeadNav />
    <!-- 中间内容部分 -->
    <div class="g_bg">
      <div class="warp">
        <div class="title">
          <h3>
            <span class="ff2">热门新碟</span>
          </h3>
        </div>
        <div class="cvrlst">
          <BigAlbum
            v-for="(item, index) in newAlbumData"
            :key="index"
            class="album"
            :newalbumdata="newAlbumData[index]"
          />
        </div>
        <div class="title" style="margintop: 10px">
          <h3>
            <span class="ff2">全部新碟</span>
          </h3>
          <div class="tab">
            <a href="javascript:void(0)" class="s_fc3">全部</a>
            <span class="line">|</span>
            <a href="javascript:void(0)" class="s_fc3">华语</a>
            <span class="line">|</span>
            <a href="javascript:void(0)" class="s_fc3">欧美</a>
            <span class="line">|</span>
            <a href="javascript:void(0)" class="s_fc3">韩国</a>
            <span class="line">|</span>
            <a href="javascript:void(0)" class="s_fc3">日本</a>
          </div>
        </div>
        <div class="cvrlst">
          <BigAlbum
            v-for="(item, index) in someAlbumData"
            :key="index"
            class="album"
            :newalbumdata="someAlbumData[index]"
          />
        </div>
        <div>
          <div class="page">
            <a
              ref="zpgi"
              v-for="(item, index) in nums"
              :key="item"
              href="javascript:void(0)"
              class="zpgi"
              @click="changePage(index)"
              >{{ item }}</a
            >
          </div>
        </div>
      </div>
    </div>
    <!-- 脚注 -->
    <Footer />
    <!-- 回到顶部 -->
    <a ref="backTop" class="m_back" href="#"></a>
  </div>
</template>

<script>
// 导入获取新碟上架接口数据的js文件
import { getAlbum, getAllAlbum } from "@/api/getAlbum";
//引入组件
import TopNav from "@/components/global/TopNav.vue";
import HeadNav from "@/components/HeadNav.vue";
import Footer from "@/components/global/Footer.vue";
import BigAlbum from "@/components/global/BigAlbum.vue";
export default {
  name: "MoreNewDiscs",
  components: {
    TopNav,
    HeadNav,
    Footer,
    BigAlbum,
  },
  data() {
    return {
      // 用来生成遍历
      nums: ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
      // 用来判断导航栏的样式
      typess: "true",
      // 用来存放从接口获取的新碟上架数据
      newAlbumData: [],
      // 用来存放每一页数量的新碟
      someAlbumData: [],
      // 用来存放请求的所有新碟
      allAlbumData: [],
    };
  },
  created() {
    //获取新碟
    getAlbum()
      .then((res) => {
        this.newAlbumData = res.data.albums.slice(0, 10);
      })
      .catch((err) => {
        console.log(err);
      });
    //传递参数
    let params = {
      limit: 315,
    };
    //获取315张新碟
    getAllAlbum(params)
      .then((res) => {
        this.allAlbumData = res.data.albums;
        this.someAlbumData = res.data.albums.slice(0, 35);
      })
      .catch((err) => {
        console.log(err);
      });
  },
  mounted() {
    let nums = this.$refs.zpgi;
    nums[0].className = "zpgi selected";
  },
  methods: {
    showTop() {
      let index = document.documentElement.scrollTop;
      if (index == 0) {
        this.$refs.backTop.style.display = "none";
      } else {
        this.$refs.backTop.style.display = "block";
      }
    },
    changePage(index) {
      let nums = this.$refs.zpgi;

      this.clearStyle();

      nums[index].className = "zpgi selected";

      let offset = index + 1;
      this.someAlbumData = [];
      this.someAlbumData = this.allAlbumData.slice(index * 35, offset * 35);
    },
    clearStyle() {
        let nums = this.$refs.zpgi
        nums.forEach(e => {
            e.className = 'zpgi'
        });
    },
  },
};
</script>

<style lang="less" scoped>
.MoreNewDiscs {
  min-width: 982px;
  background: #f5f5f5;
  display: flex;
  width: 100%;
  height: 100%;
  flex-direction: column;
}
.m_back {
  display: none;
  position: fixed;
  text-indent: -9999px;
  left: 50%;
  margin-left: 500px;
  bottom: 160px;
  width: 49px;
  height: 44px;
  background: url(../static/imgs/sprite.png) no-repeat 0 9999px;
  background-position: -265px -47px;
}
.g_bg {
  width: 980px;
  min-height: 700px;
  margin: 0 auto;
  background-color: #fff;
  border: 1px solid #d3d3d3;
  border-width: 0 1px;
}
.warp {
  padding: 40px;
  position: relative;
}
.title {
  height: 40px;
  border-bottom: 2px solid #c20c0c;
  h3 {
    float: left;
    font-size: 24px;
    line-height: 40px;
    font-weight: normal;
  }
}
.ff2 {
  font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
  font-weight: normal;
}
.cvrlst {
  width: 900px;
  padding-top: 30px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;
}
.tab {
  float: left;
  margin: 10px 0 0 17px;
  line-height: 30px;
  a {
    color: #666;
    margin: 0 3px;
  }
}
.line {
  margin: 0 10px;
  color: #ccc;
}
.page {
  margin: 20px 0;
  text-align: center;
}
.zpgi {
  height: 22px;
  padding: 0 8px;
  background: url(../static/imgs/button.png) no-repeat 0 9999px;
  background-color: #fff;
  line-height: 22px;
  margin: 0 1px 0 2px;
  display: inline-block;
  border: 1px solid #ccc;
  border-radius: 2px;
  vertical-align: middle;
}
.zpgi:hover {
  border: 1px solid black;
  text-decoration: none;
}
.zdot {
  text-align: center;
}
.zpgi.selected {
  background: url(../static/imgs/button.png) no-repeat 0 9999px;
  background-position: 0 -650px;
  border-color: #a2161b;
  color: #fff;
  cursor: default;
}
</style>






